// JavaScript Document

/**
 * import compontent 
 */
Vsg.importClass(
	[
		"Vsg.DataSourceEntity.DataSourceEntityBuilder",
		"Vsg.EntityRecord.PrelProbabilityStock"
	]
);


/**
 * init data 
 */
function init() {
	
	try {
		var $dsEntity = new Vsg.DataSourceEntity.DataSourceEntityBuilder();
		$dsEntity.setUrl( UrlMKey['pre-proba-stock']);
		$dsEntity.setEntityRecord( new Vsg.EntityRecord.PrelProbabilityStock() );	
		
		var $ds = $dsEntity.newLoadedDataSource({
			autoload:true
		});

		// --- defined the grid panel ---
    	var gridPanel = new Ext.grid.GridPanel({
        	width:700,
        	height:500,
        	store: $ds,
        	loadMask: true,

        	// grid columns
			sm:new Ext.grid.RowSelectionModel({singleSelect:true}),
			colModel:new Ext.grid.ColumnModel([
				new Ext.grid.CheckboxSelectionModel() ,
				{
					header: "上涨概率",
					width: 25,
					sortable: true,
					dataIndex: "upProbability"
				
				},
				{
					header: "日期",
					width: 25,
					sortable: true, 
					dataIndex: "date"
				},
				{
					id:"code",
					header: "股票代码",
					width: 25,
					sortable: true,
					dataIndex: "code"
				},
				{
					header: "股票名称",
					width: 25,
					sortable: true,
					dataIndex: "stockname"
				
				}				
			]),

        	// customize view config
        	viewConfig: {
            	forceFit:true
        	},

        	// paging bar on the bottom
        	bbar: new Ext.PagingToolbar({
            	pageSize: Ext.PAGE_SIZE,
            	store: $ds,
            	displayInfo: true,
            	displayMsg: '显示当前列 {0} - {1} 共 {2}页',
            	emptyMsg: "当前没有数据",
            	items:[
                	'-', {
                	pressed: true,
                	enableToggle:true,
                	text: 'Show Preview',
                	cls: 'x-btn-text-icon details',
                	toggleHandler: function(btn, pressed){
                    	var view = grid.getView();
                    	view.showPreview = pressed;
                    	view.refresh();
                	}
            	}]
        	})
    	});
		
		
		// --- defined the form panel ---
		var formPanel = new Ext.form.FormPanel({
			labelAlign: 'left',
			autoHeight:true,
			defaults:{width:200},
			height:'100%',
			border:false,
			bodyStyle:'padding:5px 5px 0',
			defaultType:'textfield',
			items:[{
				fieldLabel:'日期',
				name:'date',
				xtype:'datefield'
			}],
			buttonAlign:'center',
			buttons:[{
				text:"查 询",
				handler:function() {
					alert(123);
				}
			}]
		});
		
	
		// --- show panel ---
		new Ext.Viewport({
			layout:"border",
			items:[{
				region:"center",
				border:false,
				margins:"5 5 5 5",
				layout:"fit",
				items:[gridPanel]
			},{
				region:"west",
				width:350,
				hieht:'100%',
				border:true,
				margins:"5 5 5 5",
				layout:"form",
				items:[formPanel]
			}]
		});
		


	} catch (e) {
		alert('出现系统性错误，请联系管理人员!');
		//Ext.log("Initial UI error: " + e);
	}


	
}
// --- run the init method
Vsg.run( init );